﻿ <div class="tableform" style="width:300px;height:220px">
    <table cellpadding="0" cellspacing="0" border="0" style=" padding-top:10px;">
     <tr>
            <td><span class="input100">商品分类：</span><select id="slscategory" size="5" style="width:140px;height:140px;"></select></td>
        </tr>
         <tr>
             <td><span class="input100">显示数量：</span><input type="text" name="txtbrandmaxnum" id="txtbrandmaxnum" class="input-text" /></td>
        </tr>
        <tr><td><span class="input100"><input type="checkbox" id="ckbrandlogo" name="ckbrandlogo" onclick="CheckboxValue(this,1)" />是否显示图片</span>
        <span class="input100"><input type="checkbox" id="ckbrandtitle" name="ckbrandtitle" onclick="CheckboxValue(this,2)" />是否显示标题</span></td></tr>
    </table>
 </div>
 <script type="text/javascript">
     var isshowlogo = false; //是否显示图片
     var isshowtitle = false; //是否显示标题
     function loadEditDialogData() {
         Hidistro_Dialog.dialogContent = $(taboverlaycontent).html();
         Hidistro_Dialog.dialogShow();
         Hidistro_Dialog.dialogTitle($(ctrnamediv).html());

         $.ajax({
             url: "Handler/DesigComments.ashx",
             async: false,
             type: "post",
             data: {
                 ModelId: "commentCategory"
             },
             dataType: "json",
             success: function (msg) {
                 if (msg.success) {
                     DataBindValue(msg.Result);
                 } else {
                     art.dialog({ content: msg.Result, lock: true });
                 }
             },
             complete: function () {
                 BindCommentBrandEvent();
             }
         });

     }

     function DataBindValue(commentBrandJson) {
         if (commentBrandJson.length > 0) { //循环商品分类 
             $("#slscategory").empty();
             $("#slscategory").append("<option value='' selected='selected'>所有分类</option>");
             $.each(commentBrandJson, function (index, item) {
                 $("#slscategory").append("<option value=\"" + item.CategoryId.replace(/\s/g, "") + "\">" + FormCategoryPath(item.Depth, item.Name) + "</option>");
             });
         }
     }

     function FormCategoryPath(depath, categoryname) {
         for (var index = 1; index < depath; index++) {
             categoryname = "　　" + categoryname;
         }
         return categoryname;
     }

     function BindCommentBrandEvent() {
         if (Hidistro_designer.ElementValues != null) {
             if (Hidistro_designer.ElementValues.CategoryId != "" && Hidistro_designer.ElementValues.CategoryId != null) {
                 $("#slscategory option[value='" + Hidistro_designer.ElementValues.CategoryId + "']").attr("selected", true);
             }

             if (Hidistro_designer.ElementValues.MaxNum != "" && Hidistro_designer.ElementValues.MaxNum != null) {
                 $("#txtbrandmaxnum").val(Hidistro_designer.ElementValues.MaxNum);
             }

             if (Hidistro_designer.ElementValues.IsShowLogo == "true") {
                 $("#ckbrandlogo").attr("checked", "true");
                 isshowlogo = true;
             } else {
                 $("#ckbrandlogo").removeAttr("checked");
             }

             if (Hidistro_designer.ElementValues.IsShowTitle == "true") {
                 $("#ckbrandtitle").attr("checked", "true");
                 isshowtitle = true;
             } else {
                 $("#ckbrandtitle").removeAttr("checked");
             }
         }
     }


     function SaveElmentValue() {

         if ($("#slscategory").val().replace(/\s/g, "")!=""&&(isNaN($("#slscategory").val().replace(/\s/g, "")) || parseInt($("#slscategory").val().replace(/\s/g, "")) < 0)) {
             Hidistro_Dialog.dialogTip('error', '请选择商品分类');
             return false;
         }

         if ($("#txtbrandmaxnum").val().replace(/\s/g, "") == "") {
             Hidistro_Dialog.dialogTip('error', '显示数量不允许为空');
             return false;
         }
         if (isNaN($("#txtbrandmaxnum").val().replace(/\s/g, "")) || 
         parseInt($("#txtbrandmaxnum").val().replace(/\s/g, "")) <= 0||
         parseInt($("#txtbrandmaxnum").val().replace(/\s/g, "")) >100) {
             Hidistro_Dialog.dialogTip('error', '显示数量为0~100的正整数');
             return false;
         }

       
         $.ajax({
             url: "Handler/DesigComments.ashx",
             async: false,
             type: "post",
             data: {
                 ModelId: "editecommentbrand",
                 Param: "{\"Id\":\"" + Hidistro_designer.CurrentContentID +
                             "\",\"IsShowLogo\":\"" + isshowlogo +
                             "\",\"IsShowTitle\":\"" + isshowtitle +
                            "\",\"CategoryId\":\"" + $("#slscategory").val() +
                            "\",\"MaxNum\": \"" + $("#txtbrandmaxnum").val() + "\"}"
             },
             dataType: "json",
             success: function (msg) {
                 if (msg.success) {
                     $("#" + Hidistro_designer.CurrentContentID).replaceWith(msg.Result.ComBrand);
                     Hidistro_Dialog.dialogTip("succeed", "商品品牌标签更新成功");
                 } else {
                     Hidistro_Dialog.dialogTip("error", msg.Result);
                 }
             },
             complete: function () {
                 Hidistro_designer.BindSingleEvent(Hidistro_designer.CurrentContentID, true);
             }
         });
     }

     function CheckboxValue(objmore, typ) {
         if (typ == 1) {
             isshowlogo = objmore.checked;
         } else {
             isshowtitle = objmore.checked;
         }
     }

 </script>